<?php
	include_once("adb.php");
	
	class community extends adb{
		function community(){
			adb::adb();
		}
		
		function get_all_community(){
			$query = "select * from community";
			return $this->query($query);
		}
		
		function delete_all_community(){
			$query = "Delete from community where 1=1";
			return $this -> query($query);
		}
		
		function add_community($latitude, $longitude, $population, $household, $community_name, $subdistrict_id){
			$query = "insert into community(latitude, longitude, population, household, community_name, subdistrict_id) 
						values (' $latitude', '$longitude',' $population',' $household', '$community_name', '$subdistrict_id')";
			return $this->query($query);
		}
		
		function update_community($id,$community_name, $population, $household){

			$query = "update community set community_name='$community_name', 
						population='$population', household='$household'
					 where community_id=$id";
			return $this->query($query);
		}
		
		function delete_community($id){
			//$id = $_REQUEST["community_id"];
			$query = "delete from community where community_id=$id";
			return $this->query($query);
		}
		
		function get_community_id($id){
			//$id=$_REQUEST["community_id"];
			$query = "select * from community where community_id = $id";
			return $this->query($query);
		}
		
		function search_community($community_name){
			$query = "select * from community where community_name like '%$community_name%'";
			return $this -> query($query);
		}
		
		function subdistrict($subdistrict_id){
			$query = "select * from community where subdistrict_id = $subdistrict_id inner join subdistrict on subdistrict.subdistrict_id = community.subdistrict_id ";
			return $this -> query($query);
		}

	}
	/*
	$obj= new community();
	if(!$obj->get_all_community()){
		echo "error";
	}
	
	$row=$obj->fetch();
	while($row){
		print_r($row);
		$row=$obj->fetch();
	}*/
?>
